const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
module.exports = {
    entry: './src/index.js',
    output: {
        filename: 'bundle.js',
        path: path.resolve(__dirname, 'docs')
    },
    module: {
        rules: [{
            test: /.less$/,
            use: ['style-loader', 'css-loader', 'less-loader']
        }, {
            test: /\.(png|jpg|gif)$/,
            use: [
                {
                    loader: 'url-loader',
                    options: {
                        limit: 1,
                        name: '[name].[hash:7].[ext]',
                        outputPath: "img"
                    }
                }
            ]
        }]
    },
    plugins: [
        // https://github.com/ampedandwired/html-webpack-plugin
        // 自动将js文件注入html中
        new HtmlWebpackPlugin({
            filename: path.resolve(__dirname, './docs/index.html'),
            template: 'index.html',
            favicon: path.resolve(__dirname, './src/assets/ycy.ico'),
            inject: true
        })
    ],
    devServer: {
        compress: true,
        port: 8080
    }
};